# -*- coding: utf-8 -*-
# coding=utf-8
'''
@author: Administrator
'''
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir)

import csv
import DBCenter

'''
    初始化cellphone_recharge表的数据，分为10个城市
'''
def Run():
    csvfile = open('cellphone_recharge.csv', 'r')
    reader = csv.reader(csvfile)
    print(reader)
    for row in reader:
        insert_sql = '''
            INSERT INTO `RosefinchEC`.`cellphone_recharge`
                        (`province_id`,
                         `province_name`,
                         `Operators`,
                         `lianlian_product_code`,
                         `lianlian_product_name`,
                         `lianlian_rate`,
                         `create_user`,
                         `create_date`)
            VALUES ('%s',
                    '%s',
                    '%s',
                    '%s',
                    '%s',
                    %s,
                    'CellphoneRechargeInit',
                    NOW());
        ''' % (row[0], 
               row[1].decode('gbk').encode('utf8'), 
               row[2].decode('gbk').encode('utf8'), 
               row[3].decode('gbk').encode('utf8'),
               row[4].decode('gbk').encode('utf8'), 
               row[5]
               )
        try:
            DBCenter.rc_db.execute(insert_sql)
        except:
            print insert_sql
    
Run()
print 'success'

